home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-07-01 | 5.6 KB | 244 lines | [TEXT/MPS ] |
- MC68881 ; We will be using
- ; instructions for
- ; the 68881 chip
- MACHINE MC68020 ; optimize for the
- ; 68020, if you don't
- ; have one remove
- ; this line
-
- ScaleMult FUNC EXPORT
- ; this lets the rest
- ; of the world know
- ; about our function
-
- _Debugger OPWORD $A9FF ; this will pop us
- ; into Macs bugs so
- ; we can follow every
- ; instruction and
- ; observe the
- ; registers
-
-
- ; The following are all displacements so we
- ; can address our data on the stack, relative
- ; to the address stored in A6
-
- result EQU 20 ; two bytes for our
- ; integer result
- Scalar EQU 16 ; 4 bytes (address of
- ; the scalar)
- inMat EQU 12 ; 4 bytes (address of
- ; the input Matrix)
- outMat EQU 8
- ; 4 bytes (address of
- ; the output Matrix)
- ReturnAdd EQU 4 ; 4 bytes
- superScalar EQU -12
- ; 12 bytes (hold a
- ; place for our 68881
- ; version of the
- ; scalar)
- oldA2 EQU -14 ; old the old value
- ; of A2
- oldA3 EQU -16 ; old the old value
- ;of A3
-
-
- ; *** Add the following features (to make
- ; this a “real” program):
- ; 1) make sure the number of
- ; rows and columns in the input
- ; Matrix jives with that of the
- ; the output matrix.
- ; 2) Fix the error message to
- ; tell the Pascal Program if
- ; there was a problem, such as
- ; if: rows X columns ≠ vector
- ; size
-
- ; ***** The first “real” line of our program ; (it’s about time!)
-
- _Debugger ; jump into Macsbugs
- ; so we can follow
- ; what's going on
-
- ; move all the initial parameters off the
- ; stack from the calling routine "function
- ; ScaleMult (scalar:extended;var inMatrix,
- ; outMatrix:matrix) :error"
-
- link A6,#-12 ; push A6 (the frame
- ; pointer) onto the
- ; stack , load SP
- ; into A6, then
- ; subtract off 12
- ; bytes from A7 to
- ; make room for our
- ; variables
-
- ; *******************************************
- ; after the link instruction
- ; the stack looks as follows:
- ;
- ; high
- ; integer (2 bytes)
- ; ------------ <- 20(A6)
- ; scalar (4 bytes)
- ; ------------ <- 16(A6)
- ; inMatrix (4 bytes)
- ; ------------ <- 12(A6)
- ; oldMatrix (4 bytes)
- ; ------------ <- 8(A6)
- ; returnAddress (4 bytes)
- ; ------------ <- 4(A6)
- ; old A6 (4 bytes)
- ; ------------ <- (A6)
- ; superscalar (12 bytes)
- ; ------------ <- -12(A6)
- ; and initial (A7)
- ; low
- ;
- ; *******************************************
-
-
-
- ; now move the addresses onto the chip so we ; can work with them
-
- MOVE.L A2,-(A7) ; push A2 onto the
- ; stack to save it
- MOVE.L A3,-(A7) ; do the same to A3
- MOVE.L inMat(A6),A2
- ; get the pointer to
- ; the address of
- ; inMatrix
- MOVE.L 4(A2),A0 ; get the address of
- ; the input matrix
- ; (4 bytes from the
- ; start of our matrix
- ; data structure )
- MOVE.L outMat(A6),A2
- MOVE.L 4(A2),A1 ; get the address of
- ; the output matrix
- MOVE.L inMat(A6),A2 ; get the number of
- ; rows (first byte of
- ; Matrix record)
- MOVE.W (A2),D0
- MOVE.W 2(A2),D1 ; then get the number
- ; of columns (3rd
- ; byte of matrix
- ; record
-
- MOVE.L scalar(A6),A2
- ; we will now move
- ; the scalar to a
- ; place with a bit
- ; more room
- LEA superScalar(A6),A3
- CLR.W (A3)+
- MOVE.L (A2)+,(A3)+ ; move the first 4
- ; bytes
-
- MOVE.L (A2)+,(A3)+ ; move the next 4
- ; bytes
-
- MOVE.W (A2),(A3) ; move the last byte
-
- LEA superScalar(A6),A2
- MOVE.L (A2),D2 ; get the top
- ; long-word of
- ; the scalar, shift
- ; it, then put it
- ; back
- LSL.L #8,D2
- LSL.L #8,D2
- MOVE.L D2,(A2)
-
- FMOVE.X (A2),FP1 ; get the modified
- ; scalar and store it
- ; on the 68881
-
- Loop MOVE.L (A0),D2 ; get the current
- ; high Long word of
- ; the element from
- ; the input matrix
- LSL.L #8,D2
- LSL.L #8,D2
- MOVE.L D2,(A0)
-
- FMOVE.X (A0),FP0 ; get the current
- ; element
- FMUL.X FP1,FP0 ; multiply by the
- ; scalar
- FMOVE.X FP0,(A1) ; put the element
- ; back in RAM
- MOVE.L (A1),D2 ; now shift the high
- ; Long word back (in
- ; the output
- ; matrix,and then put
- ; it away in RAM
- LSR.L #8,D2
- LSR.L #8,D2
- MOVE.L D2,(A1)
- MOVE.L (A0),D2 ; now shift the high
- ; Long word back (in
- ; the input matrix)
- ; and then put it
- ; away
- LSR.L #8,D2
- LSR.L #8,D2
- MOVE.L D2,(A0)
-
- ADD #12,A0 ; increment the
- ; element's address
- ; (to get the next
- ; element)
- ADD #12,A1
-
- DBLT D1,Loop ; decrement the
- ; number of columns
- ; and test
- ; if we are here we have gone through one
- ; column
- MOVE.L inMat(A6),A2
- MOVE.W 2(A2),D1 ; restore the number
- ; of columns
- DBLT D0,Loop ; test if we have
- ; completed through
- ; all the rows
- ; if we are here, we have gone through all
- ; the rows
-
-
- ; since we have done our work let’s put away
- ; our toys (clear the stack of all the
- ; garbage) and go home.
-
- MOVE.L (A7)+,A3 ; pop off the old A3
- MOVE.L (A7)+,A2 ; pop off the old A2
- UNLK A6
- MOVE.L (A7)+,A0 ; save the return address
- ADD.L #12,A7 ; move the stack
- ; pointer clear all
- ; the data off the
- ; stack
-
- CLR.W (A7) ; replace the return
- ; value on the stack
- ; with ours
-
- ; ** NOTE: we are pushing a value of zero
- ; onto the stack, meaning that nothing went
- ; wrong. This is bogus and in the real
- ; version we need to fix this!
-
-
- MOVE.L A0,-(A7) ; push the return
- ; address back onto
- ; the stack
-
- RTS ; return to reality
- ; (our calling
- ; program)
- ENDF
- END
-